`
https://leetcode.cn/problems/jump-game-iii/
`

/**
 * @param {number[]} arr
 * @param {number} start
 * @return {boolean}
 */
var canReach = function (arr, start) {
  const n = arr.length
  const visited = new Array(n).fill(false)
  visited[start] = true
  const q = [start]

  // BFS
  while (q.length) {
    const cur = q.shift()
    // 到达 0
    if (arr[cur] === 0) {
      return true
    }
    // 向左跳
    const nextLeftIdx = cur - arr[cur]
    if (nextLeftIdx >= 0 && !visited[nextLeftIdx]) {
      visited[nextLeftIdx] = true
      q.push(nextLeftIdx)
    }
    //向右跳
    const nextRightIdx = cur + arr[cur]
    if (nextRightIdx < n && !visited[nextRightIdx]) {
      visited[nextRightIdx] = true
      q.push(nextRightIdx)
    }
  }

  return false
};